import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    cartList: []
  },
  mutations: {
    addCart(state,payload){
      let oldProduct = state.cartList.find(item => item.iId === payload.id);

      if (oldProduct){
        oldProduct.count += 1;
      }else {
        oldProduct.count = 1;
        state.cartList.push(payload)
      }
    }
  }
});

export default store;
